<%--
    Document   : index
    Author     : Thomas
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id="login" class="login.LoginInfo" scope="session"/>
<jsp:setProperty name="login" property="*"/>
<jsp:useBean id="member" class="login.userDBDriver" scope="session"/>

<jsp:useBean id="searchInput" class="bookDatabase_pkg.BookInfo" scope="session"/>
<jsp:setProperty name="searchInput" property="*"/>

<%@ include file="header.jsp" %>

<% searchInput.setAllNull(); %>

<!-- Content -->
	
<div id="container">
	<div id="content" role="main">

                <div id="post-0" class="post error404 not-found">
			<h1 class="entry-title"></h1>
			<div class="entry-content">
                            <p>Welcome to the eBookCafe. Please select a book from the lists below
                                to view them in more detail. We hope you find the book for you! </p>

                        <hr/>
			</div><!-- .entry-content -->
		</div><!-- #post-0 -->

		<div id="post-0" class="post error404 not-found">
			<h1 class="entry-title">Action Books</h1>
			<div class="entry-content">

    <%
        bookDatabase_pkg.bookDatabaseDriver driver = new bookDatabase_pkg.bookDatabaseDriver();
        String category = "action";
        int result = driver.databaseConnect(category);
        if(result == 0){
            //out.println("Database: " + category + " connected<br />");

            String[][] books = driver.getAllBooks();
            out.println("<ul>");
            for(int i=0; i<books.length; i++){
                out.println("<form name='bk" + books[i][0] + "' role='viewBook' method='get' id='searchform' action='book.jsp'>");
                out.println("<input type='hidden' value=" + category + " name='category' id='category' />");
                out.println("<input type='hidden' value=" + books[i][0] + " name='ISBN' id='ISBN' />");
                out.println("<a href='' onclick='document.bk" + books[i][0] + ".submit(); return false;'><li>" + books[i][1] + "</li></a>");
                out.println("</form>");
            }
            out.println("</ul>");

        }
        else{
            out.println("ERROR: Database " + category + " cannot be found!<br />");
        }
    %>
    <hr/>

			</div><!-- .entry-content -->
		</div><!-- #post-0 -->
                <div id="post-0" class="post error404 not-found">
			<h1 class="entry-title">Drama Books</h1>
			<div class="entry-content">

    <%
        driver = new bookDatabase_pkg.bookDatabaseDriver();
        category = "drama";
        result = driver.databaseConnect(category);
        if(result == 0){
            //out.println("Database: " + category + " connected<br />");

            String[][] books = driver.getAllBooks();
            out.println("<ul>");
            for(int i=0; i<books.length; i++){
                out.println("<form name='bk" + books[i][0] + "' role='viewBook' method='get' id='searchform' action='http://localhost:8080/eBookCafe/book.jsp'>");
                out.println("<input type='hidden' value=" + category + " name='category' id='category' />");
                out.println("<input type='hidden' value=" + books[i][0] + " name='ISBN' id='ISBN' />");
                out.println("<a href='' onclick='document.bk" + books[i][0] + ".submit(); return false;'><li>" + books[i][1] + "</li></a>");
                out.println("</form>");
            }
            out.println("</ul>");

        }
        else{
            out.println("ERROR: Database " + category + " cannot be found!<br />");
        }
    %>
    <hr/>

			</div><!-- .entry-content -->
		</div><!-- #post-0 -->
                <div id="post-0" class="post error404 not-found">
			<h1 class="entry-title">Comedy Books</h1>
			<div class="entry-content">

    <%
        driver = new bookDatabase_pkg.bookDatabaseDriver();
        category = "comedy";
        result = driver.databaseConnect(category);
        if(result == 0){
            //out.println("Database: " + category + " connected<br />");

            String[][] books = driver.getAllBooks();
            out.println("<ul>");
            for(int i=0; i<books.length; i++){
                out.println("<form name='bk" + books[i][0] + "' role='viewBook' method='get' id='searchform' action='http://localhost:8080/eBookCafe/book.jsp'>");
                out.println("<input type='hidden' value=" + category + " name='category' id='category' />");
                out.println("<input type='hidden' value=" + books[i][0] + " name='ISBN' id='ISBN' />");
                out.println("<a href='' onclick='document.bk" + books[i][0] + ".submit(); return false;'><li>" + books[i][1] + "</li></a>");
                out.println("</form>");
            }
            out.println("</ul>");

        }
        else{
            out.println("ERROR: Database " + category + " cannot be found!<br />");
        }
    %>
    <hr/>

			</div><!-- .entry-content -->
		</div><!-- #post-0 -->
	</div><!-- #content -->
</div><!-- #container -->

<%@ include file="sidebar.jsp" %>
	
<!-- /Content -->

<%@ include file="footer.jsp" %>
